﻿// -------------------------------------------------------------------------
//    @FileName         :    NFCityPlayerMoveExt.cpp
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-15
//    @Email			:    445267987@qq.com
//    @Module           :    NFCityPlayerMoveExt
//    @Desc             :
//
// -------------------------------------------------------------------------

#include "NFCityPlayerMoveExt.h"

#include "NFCityMapUtil.h"
#include "NFCityPlayer.h"

NFCityPlayerMoveExt::NFCityPlayerMoveExt()
{
    if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
    {
        CreateInit();
    }
    else
    {
        ResumeInit();
    }
}

NFCityPlayerMoveExt::~NFCityPlayerMoveExt()
{
}

int NFCityPlayerMoveExt::CreateInit()
{
    m_bIsAction = false;
    m_iLastSynTime = 0;
    m_bIsDance = false;
    return 0;
}

int NFCityPlayerMoveExt::ResumeInit()
{
    return 0;
}

int NFCityPlayerMoveExt::Tick(NFCityPlayer* pPlayer)
{
    CHECK_NULL(0, pPlayer);
    int iTimeNow = NF_ADJUST_TIMENOW();
    if (IsAction())
    {
        if (iTimeNow - m_iLastSynTime > 3)
        {
            NFCityMapUtil::ResetPos(pPlayer);
        }
    }
    else
    {
        m_iLastSynTime = iTimeNow;
    }
    return 0;
}

void NFCityPlayerMoveExt::ClearLastAction()
{
    m_bIsAction = false;
    m_bIsDance = false;
}

int NFCityPlayerMoveExt::InitMapData(const proto_ff::RoleMapData* pRoleMapData)
{
    CHECK_NULL(0, pRoleMapData);
    m_stMapData.FromPb(*pRoleMapData);
    return 0;
}

int NFCityPlayerMoveExt::UpdateMapData(int iMapId, Proto_Vector3 oPos, int iDirection)
{
    m_stMapData.map_desc_id = iMapId;
    m_stMapData.pos = oPos;
    m_stMapData.direction = iDirection;

    m_iLastSynTime = NF_ADJUST_TIMENOW();
    return 0;
}

int NFCityPlayerMoveExt::SetLastAction(const proto_ff::Proto_PvpSynAction* pSynAction)
{
    CHECK_NULL(0, pSynAction);
    m_stLastAction.FromPb(*pSynAction);
    m_bIsAction = true;
    m_bIsDance = false;
    return 0;
}

int NFCityPlayerMoveExt::SetDanceAction(const proto_ff::Proto_PvpSynAction* pSynAction)
{
    CHECK_NULL(0, pSynAction);
    m_stLastAction.FromPb(*pSynAction);
    m_bIsDance = true;
    return 0;
}
